package com.pifuke.adapter;

import java.util.ArrayList;
import java.util.HashMap;

import org.json.JSONObject;

import android.R.color;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
import android.text.style.ForegroundColorSpan;
import android.text.style.UnderlineSpan;
import android.util.Log;
import android.view.View;
import android.widget.HorizontalScrollView;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import cn.o.app.adapter.IItemView;
import cn.o.app.adapter.OAdapter;
import cn.o.app.adapter.OItemView;
import cn.o.app.json.JsonUtil;
import cn.o.app.net.INetTask;
import cn.o.app.net.NetTaskListener;
import cn.o.app.ui.OImageView;
import cn.o.app.ui.photo.PhotoActivity;
import cn.o.app.ui.photo.PhotoExtra;
import cn.o.app.util.OUtil;
import cn.skinapp.R;

import com.evan.common.connection.ConnectionCommon;
import com.evan.common.handler.RequestHandler;
import com.evan.common.handler.callback.HandlerCallback;
import com.lidroid.xutils.BitmapUtils;
import com.smiier.skin.ChatActivity;
import com.smiier.skin.CreateProjectCommentActivity;
import com.smiier.skin.DoctorDetailActivity;
import com.smiier.skin.KepuHaoyaoshiActivity;
import com.smiier.skin.LoginActivity;
import com.smiier.skin.ZhiliaofanganActivity;
import com.smiier.skin.constant.Constant;
import com.smiier.skin.extra.QuestionAnswerExtra;
import com.smiier.skin.intercept.RequestTaskIntercept;
import com.smiier.skin.net.FollowSetTask;
import com.smiier.skin.net.FollowSetTask.FollowSetRequest;
import com.smiier.skin.net.FollowSetTask.FollowSetResponse;
import com.smiier.skin.net.entity.QuestionAnswer;
import com.smiier.skin.net.entity.Treatment;
import com.smiier.skin.ui.BasicActivity;
import com.smiier.skin.util.GlobalSettings;
import com.smiier.skin.util.ShareUtil;
import com.smiier.skin.utils.CommonUtility;

public class QuestionDetailAdapter extends OAdapter<QuestionAnswer> {
	protected BitmapUtils mBitmapUtils;

	@Override
	protected void onContainerChanged() {
		mBitmapUtils = new BitmapUtils(getContext());
	}

	BasicActivity activity;

	public void setActivity(BasicActivity activity) {
		this.activity = activity;
	}

	@Override
	public IItemView<QuestionAnswer> getItemView() {
		// TODO Auto-generated method stub
		return new QuestionItemDetailView(getContext());
	}

	class QuestionItemDetailView extends OItemView<QuestionAnswer> {

		TextView mQuestionContent;
		TextView mLocation;
		TextView mQuestionTime;
		TextView mShouCang;
		TextView mComment;
		TextView mShare;
		LinearLayout mLlImages;
		TextView mAccept;
		RelativeLayout mAfterAccept;
		RelativeLayout mStartSession;
		RelativeLayout mStartEdit;
		TextView mAnswerTime;
		TextView mAnswerContent;
		LinearLayout mMethod;
		TextView mPatientComment;
		TextView mDoctorName;
		TextView mDoctorProfession;
		TextView mDoctorHospital;
		OImageView mDoctorImage;
		HorizontalScrollView mScrollView;
		RelativeLayout mQuestionDetail;
		RelativeLayout mCuoshiDetail;
		TextView mLevel;
		RelativeLayout mPinJia;
		LinearLayout mUnanswer;
		LinearLayout mParent;
		LinearLayout mCommentParent;
		RelativeLayout mDoctorParent;

		public QuestionItemDetailView(Context context) {
			super(context);
		}

		@Override
		public void onCreate() {
			this.setContentView(R.layout.item_question_detail);
			
			
			Log.i("testxxx", "QuestionDetailAdapter");
			
			mDoctorParent = findViewById(R.id.doctor_yijian,
					RelativeLayout.class);
			mQuestionContent = findViewById(R.id.text_content, TextView.class);
			mLocation = findViewById(R.id.text_guanzhu_num, TextView.class);
			mQuestionTime = findViewById(R.id.text_guanzhu_date, TextView.class);
			mAccept = findViewById(R.id.accept, TextView.class);
			mShouCang = findViewById(R.id.btn_guanzhu, TextView.class);
			mParent = findViewById(R.id.btn_guanzhu_parent, LinearLayout.class);
			mCommentParent = findViewById(R.id.btn_comment_parent,
					LinearLayout.class);
			mShare = findViewById(R.id.btn_share, TextView.class);
			mStartSession = findViewById(R.id.btn_huihuawenzhen,
					RelativeLayout.class);
			mStartEdit = findViewById(R.id.btn_zhiliaofangan,
					RelativeLayout.class);
			mLlImages = findViewById(R.id.ll_imgs, LinearLayout.class);
			mScrollView = findViewById(R.id.hsv_imgs,
					HorizontalScrollView.class);
			mAfterAccept = findViewById(R.id.ll_zhiliao_fangan,
					RelativeLayout.class);
			mComment = findViewById(R.id.btn_comment, TextView.class);
			mQuestionDetail = findViewById(R.id.question_detail,
					RelativeLayout.class);
			mLevel = findViewById(R.id.pingjia_tubiao, TextView.class);
			mAnswerTime = findViewById(R.id.question_time, TextView.class);
			mAnswerContent = findViewById(R.id.text_jieda_result,
					TextView.class);
			mPinJia = findViewById(R.id.pingjia_parent, RelativeLayout.class);
			mPatientComment = findViewById(R.id.text_comment_value,
					TextView.class);
			mDoctorName = findViewById(R.id.doctor_name, TextView.class);
			mDoctorProfession = findViewById(R.id.doctor_professional,
					TextView.class);
			mDoctorHospital = findViewById(R.id.doctor_hospital_name,
					TextView.class);
			mCuoshiDetail = findViewById(R.id.cuoshi_parent,
					RelativeLayout.class);
			mUnanswer = findViewById(R.id.question_unanswer, LinearLayout.class);
			mDoctorImage = findViewById(R.id.img_doctor_icon, OImageView.class);
			mMethod = findViewById(R.id.text_zhiliaocuoshi, LinearLayout.class);
			// mShare.setOnClickListener(listener);
			mParent.setOnClickListener(listener);
			mAccept.setOnClickListener(listener);
			mStartSession.setOnClickListener(listener);
			mStartEdit.setOnClickListener(listener);
			mCommentParent.setOnClickListener(listener);
			mDoctorImage.setOnClickListener(listener);
			mDoctorParent.setOnClickListener(listener);
			findViewById(R.id.btn_share_parent).setOnClickListener(listener);
		}

		@Override
		public void onResume() {
			mQuestionContent.setText(mDataProvider.Question.Content);
			mQuestionTime.setText(CommonUtility.getTimeDiff(CommonUtility
					.formatDate(mDataProvider.Question.CreateTime.toString(),
							0, 19), 0, 19));
			StringBuilder sb = new StringBuilder();
			ArrayList<String> part = mDataProvider.Question.Part;
			sb = new StringBuilder();
			for (String str : part) {
				sb.append(str).append(",");
			}
			/*
			 * if (mDataProvider.Question.Status == Question.STATUS_ANSWERED &&
			 * mDataProvider.Question.Is_Appraise == 0) {
			 * mCommentParent.setVisibility(View.VISIBLE); }
			 */
			if (mDataProvider.Is_Follow == 1) {
				mShouCang.setText("已收藏");
				mShouCang.setTextColor(activity.getResources().getColor(
						R.color.border_blue));
				mShouCang.setCompoundDrawablesWithIntrinsicBounds(0, 0,
						R.drawable.collected, 0);
				mParent.setBackgroundResource(R.drawable.bg_frame_pressed_round);
			}
			if (mDataProvider.Question.Cost != 0) {
				if (sb.length() > 1) {
					sb.replace(sb.length() - 1, sb.length(), " | ")
							.append("悬赏：￥").append(mDataProvider.Question.Cost);
				} else {
					sb.append("悬赏：￥").append(mDataProvider.Question.Cost);
				}
			} else {
				if (sb.length() > 1) {
					sb.replace(sb.length() - 1, sb.length(), "");
				}
			}
			mLocation.setText(sb.toString());

			// 暂时封存
			/*
			 * if (mDataProvider.Question.Status != 3) {
			 * mComment.setVisibility(View.VISIBLE); }
			 */

			if (mDataProvider != null
					&& GlobalSettings.sUser != null
					&& mDataProvider.Patient_User.Uid == GlobalSettings.sUser.Uid) {
				if (mDataProvider.Appraise != null) {
					mCommentParent.setVisibility(View.GONE);
				} else {
					mCommentParent.setVisibility(View.VISIBLE);
				}
			}
			if (GlobalSettings.sUser == null) {
				mCommentParent.setVisibility(View.GONE);
			}
			if (mDataProvider.Question.Status != 3) {
				/*
				 * if (mDataProvider.Appraise.Level == 1) {
				 * mLevel.setText("差评"); } else if (mDataProvider.Appraise.Level
				 * == 2) { mLevel.setText("中评"); } else
				 */

				// 已接单

				if (CommonUtility.isDoctor()) {
					mQuestionDetail.setVisibility(View.GONE);
					if ((mDataProvider.Doctor_User.Uid+"").equals(GlobalSettings.sUser.Uid+"")) {
						if (mDataProvider.Question.Status == 2) {
							mAccept.setVisibility(View.GONE);
							mAfterAccept.setVisibility(View.VISIBLE);
						} else {
							mAccept.setVisibility(View.VISIBLE);
							mAfterAccept.setVisibility(View.GONE);
						}

					} else {
						if (mDataProvider.Question.Status == 2) {
						
								mAccept.setVisibility(View.GONE);
								mAfterAccept.setVisibility(View.GONE);
						
						} else {
							mAccept.setVisibility(View.VISIBLE);
							mAfterAccept.setVisibility(View.GONE);
						}
					}
				} else {
					mQuestionDetail.setVisibility(View.VISIBLE);
					if (mDataProvider.Question.Status == 1) {
						mUnanswer.setVisibility(View.VISIBLE);
						mQuestionDetail.setVisibility(View.GONE);
					} else if (mDataProvider.Question.Status == 2) {
						mAnswerContent.setText("医生正在努力解答中...");
						mCuoshiDetail.setVisibility(View.GONE);
						mPinJia.setVisibility(View.GONE);
					}
				}

			} else {
				mQuestionDetail.setVisibility(View.VISIBLE);
				if (mDataProvider.Appraise.Level == 3) {
					mLevel.setText("好评");
					mLevel.setVisibility(View.VISIBLE);
				} else {
					mLevel.setVisibility(View.GONE);
				}
				if (mDataProvider.Appraise.Level != 3
						&& (mDataProvider.Appraise.Content == null || mDataProvider.Appraise.Content
								.trim().equals(""))) {
					mPinJia.setVisibility(View.GONE);
				}
				if (mDataProvider.Answer.Is_Hide_Answer == 1) {
					// 隐藏解答意见
					mCuoshiDetail.setVisibility(View.GONE);
					mAnswerContent.setText("医生选择解答意见不公开，仅提问者可以看到");
				} else {
					mCuoshiDetail.setVisibility(View.VISIBLE);
				}
				mAnswerContent.setText(mDataProvider.Answer.Malady);
				mMethod.removeAllViews();
				if (mDataProvider.Answer.Treatments.size() > 0) {
					for (Treatment ment : mDataProvider.Answer.Treatments) {
						TextView text = new TextView(getContext());
						final String drug = ment.Drug;
						if (drug != null && !drug.trim().equals("")) {
							SpannableString span = new SpannableString(drug
									+ "，" + ment.Advice);
							span.setSpan(new UnderlineSpan(), 0, drug.length(),
									Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
							// span.setSpan(new URLSpan("http://www.baidu.com"),
							// 0, drug.length(),
							// Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
							span.setSpan(
									new ForegroundColorSpan(Color
											.parseColor("#F47D43")), 0, drug
											.length(),
									Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
							span.setSpan(new ForegroundColorSpan(Color.BLACK),
									drug.length(), span.length(),
									Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
							text.setTextSize(13);
							text.setTextColor(color.black);
							text.setPadding(0, 7, 0, 7);
							text.setText(span);

							text.setMovementMethod(LinkMovementMethod
									.getInstance());
							text.setOnClickListener(new OnClickListener() {

								@Override
								public void onClick(View v) {
									// 好药师跳转
									Intent intent = new Intent();
									intent.putExtra("seekKey", drug);
									intent.setClass(getContext(),
											KepuHaoyaoshiActivity.class);
									getContext().startActivity(intent);
								}
							});
						} else {
							text.setText(ment.Advice);
						}
						/*
						 * if (text.getText() != null && !((String)
						 * text.getText()).equals("")) { mMethod.addView(text);
						 * }
						 */

						if (text.getText() != null
								&& (!text.getText().toString().trim()
										.equals(""))) {
							mMethod.addView(text);
						}

					}
					if (mMethod.getChildCount() <= 0) {
						mCuoshiDetail.setVisibility(View.GONE);
					}
					// Treatment ment = mDataProvider.Answer.Treatments.get(0);

					// mMethod.setText(sb.toString());

				} else {
					mCuoshiDetail.setVisibility(View.GONE);
				}
				if (mDataProvider.Appraise.Content == null
						|| mDataProvider.Appraise.Content.equals("")) {
					mPatientComment.setVisibility(View.GONE);
				} else {
					mPatientComment.setVisibility(View.VISIBLE);
					mPatientComment.setText(mDataProvider.Appraise.Content);
				}

				mAnswerTime.setText(CommonUtility.getTimeDiff(
						mDataProvider.Answer.CreateTime.toString(), 5, 10));

			}
			if ((CommonUtility.isDoctor() && CommonUtility.isCert())
					|| mDataProvider.Patient_User.Uid == GlobalSettings.sUid) {
				mLlImages.removeAllViews();
				ArrayList<String> pics = mDataProvider.Question.Pic;
				if (pics.size() > 0) {
					mLlImages.setVisibility(View.VISIBLE);
					String[] picStrs = new String[pics.size()];
					for (int i = 0; i < pics.size(); i++) {
						OImageView layout = new OImageView(activity);
						layout.setIsRoundRect(true);
						layout.setId(R.id.imgLayout_show);
						layout.setScaleType(ScaleType.CENTER_CROP);
						LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
								(int) OUtil.dp2px(activity, 70),
								(int) OUtil.dp2px(activity, 70));
						layoutParams.setMargins(0, 0,
								(int) OUtil.dp2px(activity, 8), 0);
						layout.setLayoutParams(layoutParams);

						final String path = pics.get(i) + Constant.IMG_TH;
						mBitmapUtils.display(layout,
								GlobalSettings.SERVER_IMG_URL + path);

						mLlImages.addView(layout);
						// layout.setImageFileTag(pics.getString(i)
						// + Constant.IMG_SRC);
						layout.setOnClickListener(listener_img);
						layout.setTag(i);
						layout.setTag(R.id.tag_obj, picStrs);
						picStrs[i] = ConnectionCommon.getInstance().REQUEST_PIC_PATH
								+ pics.get(i) + Constant.IMG_SRC;

					}
				} else {
					mLlImages.setVisibility(View.GONE);
				}
			} else {
				mLlImages.setVisibility(View.GONE);
			}
			if (mDataProvider.Question.Status != 1) {
				mDoctorName.setText(mDataProvider.Doctor_User.Name);
				ArrayList<String> profession = mDataProvider.Doctor_User.Professional;
				sb = new StringBuilder();
				for (String str : profession) {
					sb.append(str).append(" ");
					break;
				}
				// mBitmapUtils.display(mDoctorImage,
				// mDataProvider.Doctor_User.Pic,
				// new OBitmapLoadCallBack<View>());
				CommonUtility
						.displayHeadImage(mDoctorImage, mBitmapUtils,
								GlobalSettings.SERVER_IMG_URL
										+ mDataProvider.Doctor_User.Pic
										+ GlobalSettings.IMG_SRC, getContext()
										.getResources(),
								mDataProvider.Patient_User.Sex);
				mDoctorProfession.setText(sb.toString());
				mDoctorHospital.setText(mDataProvider.Doctor_User.Hospital);
			}

		}

		OnClickListener listener = new OnClickListener() {

			@Override
			public void onClick(final View view) {
				Intent intent;
				int id = view.getId();
				if (id == R.id.text_jiedan_doctor) {
					intent = new Intent(activity, DoctorDetailActivity.class);
					intent.putExtra(Constant.IDENTITY_KEY, view.getTag()
							.toString());
					activity.startActivity(intent);
				} else if (id == R.id.doctor_yijian) {
					intent = new Intent(activity, DoctorDetailActivity.class);
					try {
						intent.putExtra(Constant.IDENTITY_KEY,
								JsonUtil.convert(mDataProvider.Doctor_User));
						activity.startActivity(intent);
					} catch (Exception e) {
						e.printStackTrace();
					}
				} else if (id == R.id.btn_comment_parent) {
					intent = new Intent(activity,
							CreateProjectCommentActivity.class);
					QuestionAnswerExtra extra = new QuestionAnswerExtra();
					extra.setQuestionAnswer(mDataProvider);
					if (extra.putTo(intent)) {
						activity.startActivity(intent);
					}
				} else if (id == R.id.btn_zhiliaofangan) {
					if (!CommonUtility.isNull(GlobalSettings.sUser)) {
						intent = new Intent(activity,
								ZhiliaofanganActivity.class);
						try {
							intent.putExtra(Constant.IDENTITY_KEY,
									JsonUtil.convert(mDataProvider));
							activity.startActivity(intent);
						} catch (Exception e) {
							e.printStackTrace();
						}

					} else {
						activity.startActivity(new Intent(activity,
								LoginActivity.class));
					}
				} else if (id == R.id.btn_huihuawenzhen) {
					if (!CommonUtility.isNull(GlobalSettings.sUser)) {
						intent = new Intent(activity, ChatActivity.class);
						try {
							intent.putExtra(Constant.IDENTITY_KEY,
									JsonUtil.convert(mDataProvider));
							activity.startActivity(intent);
						} catch (Exception e) {
							e.printStackTrace();
						}

					} else {
						activity.startActivity(new Intent(activity,
								LoginActivity.class));
					}
				}
				/*
				 * else if (id == R.id.ll_edit_zhiliaofangan) { Object t =
				 * view.getTag(); if (!CommonUtility.isNull(t)) { intent = new
				 * Intent(activity, ZhiliaofanganActivity.class);
				 * intent.putExtra(Constant.IDENTITY_KEY, t.toString());
				 * activity.startActivity(intent); } }
				 */
				else if (id == R.id.btn_share_parent) {
					if (!CommonUtility.isNull(GlobalSettings.sUser)) {
						try {
							String url = GlobalSettings.SERVER_URL_TREATMENT
									+ "WeChat/MenuData/questionInfo/qid/"
									+ mDataProvider.Question.Qid;
							StringBuilder sbBuweiZhengzhuang = new StringBuilder();

							StringBuilder sb = new StringBuilder();
							for (String str : mDataProvider.Question.Part) {
								sb.append(str).append(",");
							}
							if (sb.length() > 1) {
								sbBuweiZhengzhuang.append(sb.replace(
										sb.length() - 1, sb.length(), ",")
										.toString());
							}
							StringBuilder sbs = new StringBuilder();
							for (String str : mDataProvider.Question.Symptom) {
								sbs.append(str).append(",");
							}
							String symptom = "";
							if (sbs.length() > 1) {
								symptom = sbs.replace(sbs.length() - 1,
										sbs.length(), ",").toString();
							}
							if (sb.length() > 1) {
								sbBuweiZhengzhuang.append("  |  ").append(
										symptom);
							}
							ShareUtil.share(activity, url,
									mDataProvider.Question.Content,
									// sbBuweiZhengzhuang.toString()
									mDataProvider.Question.Content);
						} catch (Exception e) {
							e.printStackTrace();
						}
					} else {
						activity.startActivity(new Intent(activity,
								LoginActivity.class));
					}
				} else if (id == R.id.accept) {
					if (!CommonUtility.isNull(GlobalSettings.sUser)) {
						// jieda_params.put(Constant.PARAM_API, "Question.Set");
						// jieda_params.put("Status", 2);
						// jieda_params.put(Constant.PARAM_TOKEN,
						// GlobalSettings.sToken); try {
						// jieda_params.put("Doctor_Uid",
						// GlobalSettings.sUser.Uid); }
						// jieda_params.put("qid", mDataProvider.Question.Qid);
						/*
						 * QuestionSetTask task = new QuestionSetTask();
						 * QuestionSetRequest req = new QuestionSetRequest();
						 * req.qid = mDataProvider.Question.Qid; req.Doctor_Uid
						 * = GlobalSettings.sUser.Uid; req.Status = 2; req.Token
						 * = GlobalSettings.sToken; task.setRequest(req);
						 * task.addListener(new
						 * NetTaskListener<QuestionSetTask.QuestionSetRequest,
						 * QuestionSetTask.QuestionSetResponse>() {
						 * 
						 * @Override public void onException(
						 * INetTask<QuestionSetRequest, QuestionSetResponse>
						 * task, Exception e) {
						 * 
						 * }
						 * 
						 * @Override public void onComplete(
						 * INetTask<QuestionSetRequest, QuestionSetResponse>
						 * task, QuestionSetResponse response) { if
						 * (!CommonUtility.isNull(response)) {
						 * 
						 * if (response.ResultCode == 200) {
						 * CommonUtility.tip(activity, "您已经成功接单"); JSONObject
						 * oo; try { oo = new JSONObject(JsonUtil
						 * .convert(response.Head));
						 * 
						 * oo.getJSONObject("Question").put( "Status", 2);
						 * LinearLayout ll_zhiliao_huihua = (LinearLayout) view
						 * .getTag(R.id.tag_obj1); ll_zhiliao_huihua
						 * .setVisibility(View.VISIBLE);
						 * view.setVisibility(View.GONE);
						 * oo.getJSONObject("Question").put( "Doctor_Uid",
						 * GlobalSettings.sUser.Uid); JSONObject jiedan_doctor =
						 * oo .getJSONObject("Doctor_User");
						 * jiedan_doctor.put("Name", GlobalSettings.sUser.Name);
						 * jiedan_doctor .put("Professional",
						 * GlobalSettings.sUser.Professional); jiedan_doctor
						 * .put("Hospital", GlobalSettings.sUser.Hospital);
						 * oo.put("Doctor_User", jiedan_doctor); Intent data =
						 * new Intent( Constant.RECIVER_QUESTION);
						 * data.putExtra( Constant.IDENTITY_KEY, oo.toString());
						 * activity.sendBroadcast(data);
						 * 
						 * data = new Intent( Constant.RECIVER_CHAT_LIST);
						 * activity.sendBroadcast(data); } catch (Exception e) {
						 * e.printStackTrace(); } } else { try {
						 * CommonUtility.tip(activity, response.ResultMessage);
						 * } catch (Exception e) { CommonUtility.tip(activity,
						 * "接单失败"); } } } }
						 * 
						 * }); activity.add(task);
						 */

						HashMap<String, Object> jieda_params = new HashMap<String, Object>();
						jieda_params.put(Constant.PARAM_API, "Question.Set");
						jieda_params.put("Status", 2);
						jieda_params.put(Constant.PARAM_TOKEN,
								GlobalSettings.sToken);
						try {
							jieda_params.put("Doctor_Uid",
									GlobalSettings.sUser.Uid);
						} catch (Exception e) {
							e.printStackTrace();
						}
						jieda_params.put("qid", mDataProvider.Question.Qid);
						RequestTaskIntercept.requestIntercept(activity,
								Constant.URL.REQUEST, new RequestHandler(
										activity, new HandlerCallback() {

											@Override
											public void callback(Object o) {
												if (!CommonUtility.isNull(o)) {
													JSONObject object = (JSONObject) o;
													if (CommonUtility
															.response200(object)) {
														CommonUtility.tip(
																activity,
																"您已经成功接单");
														
														
														Log.i("testaccept", "成功接单");
														Intent intent = new Intent();
														intent.setAction(Constant.RECIVER_MYIFNO_TAB_NOREAD);
														intent.putExtra("chat", true);
														getContext().sendBroadcast(intent);
														
														Intent badgeIntent = new Intent();
													    badgeIntent.setAction(Constant.RECIVER_MYIFNO_ITEM_NOREAD);
													    badgeIntent.putExtra("chat", true);
													    getContext().sendBroadcast(badgeIntent);
														
														/**
														 * 显示after
														 */

														mAccept.setVisibility(View.GONE);
														mAfterAccept
																.setVisibility(View.VISIBLE);

													} else {
														try {
															CommonUtility
																	.tip(activity,
																			object.getString("ResultMessage"));
														} catch (Exception e) {
															CommonUtility.tip(
																	activity,
																	"接单失败");
														}
													}
												}
											}
										}), jieda_params);

					} else {
						activity.startActivity(new Intent(activity,
								LoginActivity.class));
					}

				} else if (id == R.id.img_doctor_icon) {
					CommonUtility.toPersonHomeActivity(activity,
							mDataProvider.Patient_User);
				} else if (id == R.id.btn_guanzhu_parent) {
					if (!CommonUtility.isNull(GlobalSettings.sUser)
							&& GlobalSettings.sToken != null) {

						final boolean isGuanzhu = mShouCang.getText()
								.toString().equals("已收藏");
						FollowSetTask task = new FollowSetTask();
						FollowSetRequest req = new FollowSetRequest();
						ArrayList<Long> qids = new ArrayList<Long>();
						task.setRequest(req);
						qids.add(mDataProvider.Qid);
						req.qids = qids;

						req.token = GlobalSettings.sToken;
						req.method = isGuanzhu ? "cancle" : "add";
						mShouCang.setEnabled(false);
						task.addListener(new NetTaskListener<FollowSetTask.FollowSetRequest, FollowSetTask.FollowSetResponse>() {

							@Override
							public void onComplete(
									INetTask<FollowSetRequest, FollowSetResponse> task,
									FollowSetResponse response) {
								mShouCang.setEnabled(true);
								if (!CommonUtility.isNull(response)
										&& response.ResultCode == 200) {
									CommonUtility.toast(activity,
											isGuanzhu ? "取消收藏成功" : "收藏问题成功");
									mShouCang.setText(isGuanzhu ? "收藏" : "已收藏");
									if (!isGuanzhu) {
										mShouCang.setTextColor(activity
												.getResources().getColor(
														R.color.border_blue));
										mShouCang
												.setCompoundDrawablesWithIntrinsicBounds(
														0, 0,
														R.drawable.collected, 0);
										mParent.setBackgroundResource(R.drawable.bg_frame_pressed_round);
									} else {
										mShouCang.setTextColor(activity
												.getResources().getColor(
														R.color.white));
										mShouCang
												.setCompoundDrawablesWithIntrinsicBounds(
														0, 0,
														R.drawable.collection,
														0);
										mParent.setBackgroundResource(R.drawable.round_btn_blue);
									}
									try {
										JSONObject oo = JsonUtil
												.convertToObject(mDataProvider);
										oo.put("Is_Follow", isGuanzhu ? 0 : 1);
										int guanzhuNum = oo
												.getInt("FollowerCount");
										oo.put("FollowerCount",
												isGuanzhu ? guanzhuNum - 1
														: guanzhuNum + 1);

										Intent data = new Intent(
												Constant.RECIVER_QUESTION);
										data.putExtra(Constant.IDENTITY_KEY,
												oo.toString());
										activity.sendBroadcast(data);
									} catch (Exception e) {
										e.printStackTrace();
									}

								}
							}

							@Override
							public void onException(
									INetTask<FollowSetRequest, FollowSetResponse> task,
									Exception e) {

							}
						});
						activity.add(task);
					} else {
						activity.startActivity(new Intent(activity,
								LoginActivity.class));
					}
				}
			}
		};

		OnClickListener listener_img = new OnClickListener() {

			@Override
			public void onClick(View view) {
				int position = (Integer) view.getTag();
				String[] pics = (String[]) view.getTag(R.id.tag_obj);
				PhotoExtra extra = new PhotoExtra();
				extra.setDisplayedIndex(position);
				extra.setPhotos(OUtil.asArrayList(pics));
				Intent intent = new Intent(activity, PhotoActivity.class);
				extra.putTo(intent);
				activity.startActivity(intent);
			}
		};

	}

}
